<template>
  <div class="demo-collapse">
    <el-collapse >
        <el-collapse-item title="报名模块设置" name="1">
          <el-form :model = "form">
            <el-form-item label="清空报名信息">
              <el-button type="primary" @click="handleEnroll">清空</el-button>
            </el-form-item>
            <el-form-item label="考试分数线">
              <el-input v-model="form.examScoreLine" placeholder="请输入考试分数线" style="width: 220px"></el-input>
              <el-button type="primary" @click="handleExamScoreLine">提交</el-button>
            </el-form-item>
            <el-form-item label="面试分数线">
              <el-input v-model="form.interviewScoreLine" placeholder="请输入面试分数线" style="width: 220px"></el-input>
              <el-button type="primary" @click="handleInterviewScoreLine">提交</el-button>
            </el-form-item>
          </el-form>
        </el-collapse-item>
    </el-collapse>
  </div>
</template>

<script lang="ts" setup>
import {ElMessage, ElMessageBox} from "element-plus";
import {checkExamScoreLine, checkInterviewScoreLine, enroll} from "@/apis/system/config";
import {reactive, toRefs} from "vue";
const data = reactive({
  form: {
    examScoreLine : null,
    interviewScoreLine : null
  },
});
const {form} = toRefs(data);
function handleEnroll(){
  ElMessageBox.alert('请确认是否删除？确认后将一键处删除当前报名系统的所有笔试和面试信息，请谨慎使用！！！', '提示', {
    confirmButtonText: '确定',
    callback: (action: string) => {
      if (action === 'confirm') {
        enroll().then(response => {
          if(response.data.code === 200){
            ElMessage({ type: 'success', message: '删除成功' })
          }else {
            ElMessage({ type: 'error', message: response.data.msg })
          }
        })
      }
    }
  });
}
function handleExamScoreLine(){
  ElMessageBox.alert('请确认分数线？确认后将一键更新考试状态，低于分数线将变为未通过，大于等于变为已通过', '提示', {
    confirmButtonText: '确定',
    callback: (action: string) => {
      if (action === 'confirm') {
        checkExamScoreLine(form.value.examScoreLine).then(response => {
          if(response.data.code === 200){
            ElMessage({ type: 'success', message: '已批量修改考试状态成功' })
          }else {
            ElMessage({ type: 'error', message: response.data.msg })
          }
        })
      }
    }
  });
}
function handleInterviewScoreLine(){
  ElMessageBox.alert('请确认分数线？确认后将一键更新面试状态，低于分数线将变为未通过，大于等于变为已通过', '提示', {
    confirmButtonText: '确定',
    callback: (action: string) => {
      if (action === 'confirm') {
        checkInterviewScoreLine(form.value.interviewScoreLine).then(response => {
          if(response.data.code === 200){
            ElMessage({ type: 'success', message: '已批量修改面试状态成功' })
          }else {
            ElMessage({ type: 'error', message: response.data.msg})
          }
        })
      }
    }
  });
}
</script>

<style scoped>
</style>
